<script setup lang="ts">
import {markRaw, onMounted, ref} from "vue";
import type {EChartsOption, EChartsType} from "echarts";
import * as echarts from "echarts";
import {useGetPieDataApi} from "@/api";
import 'echarts-wordcloud'
import type {Pie} from "@/interface";

const pie = ref()
const option = ref<EChartsOption>()
const myChart = ref<EChartsType>()
const pieData = ref<Pie>({
  data:[]
})
const init = async () => {
  const {data:res} = await useGetPieDataApi()
  pieData.value = res
  myChart.value = markRaw(echarts.init(pie.value));
  draw();
}
const draw = () => {
  option.value = {
    title: {
      text: '不同朝向的二手房占比',
      left: 'center'
    },
    tooltip: {
      trigger: 'item',
      formatter:'{a}<br/>{b}:{d}%'
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        name: '占比',
        type: 'pie',
        radius: '50%',
        data: pieData.value.data,
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  }
  myChart.value.setOption(option.value, {notMerge: true});
}
onMounted(() => {
  init()
})
</script>

<template>
  <div ref="pie" class="pie">
  </div>
</template>

<style scoped>
.pie{
  width: 100%;
  height: 100%;
}
</style>